


import os

import json

from urllib import request,parse

class Chat(object):

    key = "306424f3584442ccbc72e21e1543f8dc" # turing123网站

    apiurl = "http://www.tuling123.com/openapi/api?"

    def init(self):

        os.system("clear")

        print("尽情调教把!")

        print("-------------------------------")

    def get(self):

        print("> ",)

        info = input()

        if(info == 'q' or info == 'exit' or info == "quit"):

            print("- Goodbye")

        return self.send(info)

    def send(self, info):

        url = self.apiurl + 'key=' + self.key + '&' + 'info=' + parse.quote(info)

        re = request.urlopen(url).read()

        re_dict = json.loads(re)

        text = re_dict['text']

        print('- ', text)

        self.get()

if __name__ == "__main__":

    chat = Chat()

    chat.init()

    chat.get()











#拼接post的url地址
def get_postUrl(params):
	urlstr = 'https://pan.baidu.com/api/sharedownload?'
	params = json.loads(params)
	urlstr += 'sign=' + str(params.get('sign')) + ''
	urlstr += '&timestamp=' + str(params.get('timestamp')) + ''
	urlstr += '&bdstoken=' + str(params.get('bdstoken')) + ''
	urlstr += '&channel=chunlei'
	urlstr += '&clienttype=0'
	urlstr += '&web=1'
	urlstr += '&app_id=250528'
	return urlstr
	
#拼接post携带的参数
def get_postData(params):
	postdata = {}
	params = json.loads(params)
	postdata["encrypt"] = 0
	postdata["product"] = "share"
	postdata["uk"] = str(params.get("uk"))
	postdata["primaryid"] = str(params.get("shareid"))
	postdata["fid_list"] = "[" + str(params['file_list']['list'][0].get('fs_id')) + "]"
	return postdata
  

